package com.jml.juc;


import java.util.concurrent.locks.LockSupport;

/**
 *
 */
public class LockSupportDemo {

    static Lock1 lock1 = new Lock1();
    static Lock2 lock2 = new Lock2();
    static Lock3 lock3 = new Lock3();

    static class Lock1 extends Thread{
        @Override
        public void run() {
            try {
                System.out.println(Thread.currentThread().getName()+"begin");
                Thread.sleep(1000);

                LockSupport.park();

                System.out.println(Thread.currentThread().getName()+"end");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    static class Lock2 extends Thread{
        @Override
        public void run() {
            try {
                System.out.println(Thread.currentThread().getName()+"begin");
                Thread.sleep(1000);

                LockSupport.park();

                System.out.println(Thread.currentThread().getName()+"end");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    static class  Lock3 extends Thread{
        @Override
        public void run() {
            try {
                System.out.println(Thread.currentThread().getName()+"begin");
                Thread.sleep(1000);

                LockSupport.park();

                System.out.println(Thread.currentThread().getName()+"end");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }


    public static void main(String[] args) throws InterruptedException {



        lock1.start();
        lock2.start();
        lock3.start();

        LockSupport.unpark(lock1);
        LockSupport.unpark(lock2);
        LockSupport.unpark(lock3);

        System.out.println(11);

        Thread.sleep(5000);

        System.out.println(22);



    }

}
